package com.woyou.ui.component;

import com.citaq.ideliver.R;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class UserInfoDialog {
	static EditText et;
	static StringBuilder sb = new StringBuilder();
	static Window window;
	static Button ok_button, cancle_button;
	public TextView string_ed;
	public static Dialog dialog;
	AlertDialog dlg1 = null;
	
	public void Dialog(final Context con,final TextView textArray, final int ID, String string) {
		if (dialog != null && dialog.isShowing()) {
			return;
		}
		LayoutInflater factory = LayoutInflater.from(con);
		// 得到自定义对话框
		final View DialogView = factory.inflate(R.layout.pop_userinfodialog, null);
		dialog = new Dialog(con, R.style.FullHeightDialog);
		Window dialogWindow = dialog.getWindow();
		dialogWindow.setGravity(Gravity.BOTTOM);

		string_ed = (TextView) DialogView.findViewById(R.id.string_textView);
		et = (EditText) DialogView.findViewById(R.id.dialog_editText);
		ok_button = (Button) DialogView.findViewById(R.id.ok_button);
		cancle_button = (Button) DialogView.findViewById(R.id.cancle_button);
		
		et.setText(textArray.getText().toString());
		string_ed.setText(string);
		et.setSelection(textArray.getText().toString().length());
		sb = sb.delete(0, sb.length());
		
		ok_button.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				switch (ID) {
				case R.id.fm_myinfo_nametext:
					if (et.getText().toString().length()>4)
					{
						Toast.makeText(con, "输入的字符过长", 2).show();;
					}
					else
					{
						textArray.setText(et.getText().toString());
						dialog.dismiss();
					}
					break;
				default:
					break;

				}
			}
		});
		cancle_button.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				dialog.dismiss();
			}
		});
		dialog.setContentView(DialogView);
//		dialog.setCanceledOnTouchOutside(true);// 设置点击Dialog外部任意区域关
		dialog.setCancelable(false);
		dialog.show();
	}
}
